using System;
using System.Collections.Generic;
using System.Text;
using TrainTicket.DAO;
using TrainTicket.VO;
using System.Data;

namespace TrainTicket.TRAIN
{    
    public class NewsTRAIN
    {
        NewsDAO _newsDAO;
        public NewsTRAIN()
        {
            _newsDAO = new NewsDAO();
        }

        public DataTable GetNewsByTitle(string title)
        {
            return _newsDAO.GetNewsByTitle(title);
        }

        public List<News> GetAllNews()
        {
            List<News> ListNews = new List<News>();

            DataTable dbTable = new DataTable();
            dbTable = _newsDAO.GetAllNews();

            foreach (DataRow dr in dbTable.Rows)
            {
                News news = new News();

                news.NewID = int.Parse(dr["NewID"].ToString());
                news.Title = dr["Title"].ToString();
                news.Description = dr["Description"].ToString();
                news.NewContent = dr["NewsContent"].ToString();
                news.Images = dr["Images"].ToString();
                news.Status = int.Parse(dr["Status"].ToString());

                ListNews.Add(news);
            }

            return ListNews;
        }

        public DataTable GetAllNewss()
        {
            return _newsDAO.GetAllNews();
        }

        public DataTable GetNewsById(int NewID)
        {
            return _newsDAO.GetNewsById(NewID);
        }

        public DataTable GetDetailNewsMax()
        {
            return _newsDAO.GetDetailNewsMax();
        }

        public int InsertNews(News news)
        {
            return _newsDAO.InsertNews(news);
        }

        public int DeleteNews(int NewsID)
        {
            return _newsDAO.DeleteNews(NewsID);
        }

        public int UpdateNews(News news)
        {
            return _newsDAO.UpdateNews(news);
        }

        public DataSet GetPagingSQL(int currPage, int recodperpage, int Pagesize)
        {
            return _newsDAO.GetPagingSQL(currPage, recodperpage, Pagesize);
        }
    }
}
